home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / optimr.zip / OPTIMER.DOC < prev    next >
Text File  |  1990-01-15  |  3KB  |  77 lines

  1. OPTIMER - Routines for high-resolution timing of events
  2. -------------------------------------------------------
  3. Brian Foley and Kim Kokkonen
  4. TurboPower Software
  5. 1/90
  6. Version 1.0
  7. Released to the public domain
  8.  
  9. Overview
  10. ------------------------------------------------------------------------------
  11. One problem commonly faced when trying to run benchmarks on a PC is that, by
  12. default, the system clock is accurate only to 1/18th of a second. The OPTIMER
  13. unit provides a simple and convenient means of timing events with microsecond
  14. resolution. It does this by reprogramming the timer chip, but the gory details
  15. are hidden from you. OPTIMER automatically reprograms the timer before your
  16. program starts, then restores it to its normal state when your program ends.
  17. Unless your program is working with the timer chip at a very low level, no
  18. incompatibilities should arise, nor should the performance of your program
  19. change.
  20.  
  21. Using OPTIMER
  22. ------------------------------------------------------------------------------
  23. OPTIMER is very easy to use. You just add it to your program's USES statement
  24. and call the ReadTimer function when you are ready to start/stop timing. For a
  25. simple demonstration of how to use OPTIMER, see BENCH.PAS.
  26.  
  27. OPTIMER interfaces the following routines:
  28.  
  29.   function ReadTimer : LongInt;
  30.     {-Read the timer with 1 microsecond resolution}
  31.  
  32.   function ElapsedTime(Start, Stop : LongInt) : Real;
  33.     {-Calculate time elapsed (in milliseconds) between Start and Stop}
  34.  
  35.   function ElapsedTimeString(Start, Stop : LongInt) : string;
  36.     {-Return time elapsed (in milliseconds) between Start and Stop as a string}
  37.  
  38.   procedure InitializeTimer;
  39.     {-Reprogram the timer chip to allow 1 microsecond resolution}
  40.  
  41.   procedure RestoreTimer;
  42.     {-Restore the timer chip to its normal state}
  43.  
  44. The first three of these are probably the only ones you'll ever need to use.
  45. InitializeTimer is executed automatically before your program begins,
  46. RestoreTimer when it ends. You shouldn't call these yourself unless you want
  47. to reset the timer to its normal state temporarily, as you might before using
  48. the Exec procedure in the DOS unit:
  49.  
  50.    RestoreTimer;
  51.    Exec();
  52.    InitializeTimer;
  53.  
  54. Limitations
  55. -----------
  56. Because long integers are used to represent time, OPTIMER cannot be used to
  57. time events longer than about 60 minutes:
  58.  
  59.    4,294,967,295 (= $FFFFFFFF, largest unsigned value represented by longint)
  60.  /     1,193,181 (timer resolution in counts/second)
  61.  ---------------
  62.            3,599
  63.          /    60 (seconds/minute)
  64.          -------
  65.             59.9 minutes
  66.  
  67. This should hardly be a problem, however, since an event longer than an hour
  68. presumably doesn't need to be timed with 1-microsecond accuracy anyway.
  69.  
  70. Also note that the process of reading the time takes time. Hence, results of
  71. timing very short events will be skewed by the overhead of reading the timer.
  72. OPTIMER executes a calibration routine to try to compensate for this overhead
  73. as much as possible. This routine estimates the amount of time required to
  74. read the timer twice, and uses this value in ElapsedTime and ElapsedTimeString
  75. to adjust for the overhead. Even so, you should expect an error due to
  76. overhead of about 1-4 ms.
  77.